/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.model.admin;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Lu Yuanbin
 */
@Entity
@Table(name = "xtdgroup")
@NamedQueries({
    @NamedQuery(name = "Xtdgroup.findAll", query = "SELECT x FROM Xtdgroup x")})
public class Xtdgroup implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Column(name = "display_name")
    private String displayName;
    @JoinTable(name = "xtdrole", joinColumns = {
        @JoinColumn(name = "groupname", referencedColumnName = "name")}, inverseJoinColumns = {
        @JoinColumn(name = "username", referencedColumnName = "username")})
    @ManyToMany
    private Collection<Xtduser> xtduserCollection;

    public Xtdgroup() {
    }

    public Xtdgroup(String name) {
        this.name = name;
    }

    public Xtdgroup(String name, String dispalyName) {
        this.name = name;
        this.displayName = dispalyName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

//    public Collection<Xtduser> getXtduserCollection() {
//        return xtduserCollection;
//    }
//
//    public void setXtduserCollection(Collection<Xtduser> xtduserCollection) {
//        this.xtduserCollection = xtduserCollection;
//    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (name != null ? name.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Xtdgroup)) {
            return false;
        }
        Xtdgroup other = (Xtdgroup) object;
        if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.xtd.model.Xtdgroup[name=" + name + "]";
    }

    /**
     * @return the xtduserCollection
     */
    public Collection<Xtduser> getXtduserCollection() {
        return xtduserCollection;
    }

    /**
     * @param xtduserCollection the xtduserCollection to set
     */
    public void setXtduserCollection(Collection<Xtduser> xtduserCollection) {
        this.xtduserCollection = xtduserCollection;
    }
}
